import Vue from 'vue'
import Router from 'vue-router'

// 组件
import City from './views/City'


// 注册使用路由
Vue.use(Router)
// 路由组件
 const router =  new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      // 路由匹配路径
      path: '/',
      name: 'home', // 路由名称
      component: () => import('./views/Home.vue')  // 路由组件的按需加载提高性能
    },
    {
      path: '/city',
      name: 'citt',
      component:City
    },
    {
      path: '/detail/:id',
      name: 'detail',
      component: () => import('./views/Detail/Detail')
    }
  ],
  // 路由跳转让页面恢复到初始滚动位置
   scrollBehavior (to, from, savedPosition) {
     return { x: 0, y: 0 }
   }
})
// router.beforeEach(
//   (to, from, next) => {
//     document.documentElement.scrollTop = 0
//     next()
//   }
//
//   )

export default router